package com.miracle9.game.dao;
import com.miracle9.game.entity.LackDesk;
import java.util.List;
import org.hibernate.Query;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

@Repository
public class LackDeskServiceDao extends SqlOperating<LackDesk, Integer>
{
  @Cacheable(value={"springCache"}, key="'getAllLackDesk'")
  public List<LackDesk> getLackDesks()
  {
    return q_CreateSqlList("from LackDesk  order by roomId desc,orderBy", new Object[0]);
  }
  
  @CacheEvict(value={"springCache"}, key="'getAllLackDesk'")
  public void updateSumIfById(int id)
  {
    if (id == -1) {
    	q_CreateSql("update LackDesk set sumYaFen=0,sumDeFen=0", new Object[0]).executeUpdate();
    } else {
    	q_CreateSql("update LackDesk set sumYaFen=0,sumDeFen=0 where id=?", new Object[] { Integer.valueOf(id) }).executeUpdate();
    }
  }
  
  @CacheEvict(value={"springCache"}, key="'getAllLackDesk'")
  public void save(LackDesk lackDesk)
  {
    update(lackDesk);
  }
  
  @CacheEvict(value={"springCache"}, key="'getAllLackDesk'")
  public void updateOrderByById(int id, int index)
  {
	  q_CreateSql("update LackDesk set orderBy=? where id=?", new Object[] { Integer.valueOf(index), Integer.valueOf(id) }).executeUpdate();
  }
  
  public void updateStateById(int id, int state)
  {
	  q_CreateSql("update LackDesk set state=? where id=?", new Object[] { Integer.valueOf(state), Integer.valueOf(id) }).executeUpdate();
  }
}
